perm filename ENGL.TOP[AM,DBL] blob sn#161741 filedate 1975-05-30 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	Description of the top level of control, and representation, in AM.
C00010 00003	When space is tight, or in order to clean things up to make a file:
C00015 ENDMK
C⊗;
Description of the top level of control, and representation, in AM.

There are 3 basic Being functions:

GETB	(Getb B P) must fetch the contents of part P of Being B.
APPLYB	(Applyb B P A1 A2...) must execute the part P of Being B, with arguments
		bound to A1, A2,...
SETB	(Setb B P Q) must replace the contents of part P of Being B with Q.

In addition, the function GETP will be used definitely to retrieve utility
	information about the BEING (e.g., FROM-FILE, EXPR, CODE, CHANGED).

Notice that SETB must work properly if P is an executable part: SETB may have to
redefine B (e.g.), in order to ensure that APPLYB(B,P) will use the new code Q.

This is almost data-less programming (data-structure-independent). Some possibilities
for the 3 functions are:

1. GETB ≡ GET		Part name/value pairs stored as the value of B.
   SETB ≡ PUTL
   APPLYB ≡ (λ (B P A1...) (Apply* (Getb B P) A1...))

2. GETB ≡ GETP		Part name/value pairs stored on the property list of B.
   SETB ≡ PUT
   APPLYB ≡ (λ (B P A1...) (Apply* (List 'λ (Gethash P Args) (Getb B P)) A1...))

3. GETB ≡ (λ (B P BP) 
		(Setq BP (Glue B P))
		(Cond 	((Getd BP) (Apply* BP))
			((And (Loadfns BP (Getp BP 'From-file))
			      (Getd BP)
			      (Apply* BP]
   
   SETB ≡ [λ (B P Q) 
		(Setq BP (Glue B P))
		(Putd BP (List 'λ (Gethash P Args) Q]

   APPLYB ≡ (λ (B P) (Getb B (Pack (List 'C- P))))

   where Glue can be, e.g., (Pack (List B '- P)), or 
			    (Gethash B (Eval P)) which uses up the parts' value cells.
   where each part of each BEING is treated as a function in its own right.

4. GETB ≡ (λ (B P BP) 
		(Setq BP (Glue B P))
		(Cond 	((Neq (Car BP) 'Nobind)  BP)
			((And (Loadvars BP (Getp B 'From-file))
			      (Neq (Car BP) 'Nobind)
			      BP]
   
   SETB ≡ [λ (B P Q) 
		(Set (Glue B P) Q]

   APPLYB ≡ (λ (B P BP) 
		(Setq BP (Gluec B P))
		(Cond 	((Neq (Car BP) 'Nobind)  BP)
			((And (Loadvars BP (Getp B 'From-file))
			      (Neq (Car BP) 'Nobind)
			      BP]
   
   where Glue can be, e.g., (Pack (List B '- P)), or 
			    (Gethash B (Eval P)).
   where Gluec can be (Pack (List B '-C- P)), or (Gethash B (Eval (Gethash P prec))),
		or, more generally, (Glue B (Glue 'C P)).

   where each part of each BEING is treated as a variable in its own right.


5. GETB ≡ APPLY*

   SETB ≡ (λ (B P Q bold cp)
		(Cond ((Nlistp (Getd B))
		        (Setq bold (Pack (List B '-old)))
			(Movd B bold T)
			(Putd B (Subst B 'bname trivb))))
	      	(Attach (List P (Allq Q)) (PVS B)))
		(Cond ((Setq cp (Gethash P prec))
			(Attach (List cp Q) (PVS B]

   APPLYB ≡ (λ (B P) (Getb B (Prec P)))

   where Prec can be (Pack (List '-C- P)), or (Gethash P Prec),
		or, more generally, (Glue  'C P)).

   where PVS accesses the (part-name part-value) pairs in the defn of the Being,
	so we might define PVS as (λ (B) (CDDR (CADDR (GETD B)))).

   this scheme has each Being be a big selectq, with keys as part names.


6. GETB ≡ GET		Part name/value pairs stored as the value of B.
   SETB ≡ (λ (B P Q  bold  pv pvl)
		(Putl B P Q)
		(Cond ((Gethash P prec)
			(Cond ((Nlistp (Getd B))
			        (Setq bold (Pack (List B '-old)))
				(Movd B bold T)
				(Putd B (Subst B 'bname trivb))))
			(Cond ((Setq pv (assoc P (Setq pvl (PVS B)))
				(Rplacd pv (list Q)))
			      (T (Attach (List P Q) pvl]
		
   APPLYB ≡ APPLY*


7. GETB ≡ GETP		Part name/value pairs stored as the value of B.
   SETB ≡ (λ (B P Q  bold  cp)
		(Put B P Q)
		(Cond ((Setq cp (Gethash P prec))
			(Cond ((Nlistp (Getd B))
			        (Setq bold (Pack (List B '-old)))
				(Movd B bold T)
				(Putd B (Subst B 'bname trivb))))
		        (Attach (List cp Q) (PVS B]
		
   APPLYB ≡ (λ (B P A1...) (Apply* B (Gethash P prec) A1...))


8. GETB ≡ GET		Part name/value pairs stored as the value of B.
   SETB ≡ (λ (B P Q)
		(Putl B P Q)
		(Cond ((Gethash P prec)
			(Set-compile1-flags)
			(Compile1 (Cond ((Gethash B P))
	  		                (T (Puthash B P (Pack (List B '- P)))))
			          (List 'λ (Gethash P args) Q]
				
   APPLYB ≡ (λ (B P A...)  (Apply* (Gethash B P) A...))

   So each executable part is a separate function.

When space is tight, or in order to clean things up to make a file:

CONDENSEB	This takes a Being and merges all its fixups into it.

For example, for #6 on the last page, we could define

Condenseb (λ (B pvl1 pvl2 pvl3)
		(Cond ((Nlistp (Getd B)) T)
		      (T 
			(Setq pvl1 (PVS B))
			(Loadfns B (Getp B 'from-file) T)(discard old defn)
			(Setq pvl2 (PVS B))
			(Mapc pvl1 (Function (λ (pv)
					(Cond ((Setq pvl3 (Assoc (Car pv) pvl2))
						(Rplacd pvl3 (Cdr pv)))
					      (T 
						(Attach pv pvl2)))
			    )))
		))
	)


For #6, we would Dreverse pvl1 when we get it, and probably lop off the Car as well.

The actual dumping, for making a file, could be handled by COMS
(in the proper fileCOMS variable). For #6 on the last page, we would want to
save all properties of a BEING, its value, and its definition.

Most of the hash table contents, etc. can be done by an initialization routine.

Finally, we need to plan out in advance how we would convert from one representation
to another (perhaps one not even thought of yet). Clearly, we must redefine
Getb, Setb, Applyb, and probably Condenseb.
Notice that none of the contents of any of the Beings' parts would need modification:
Since they only involve calls on Getb,..., they never notice that the representation
has changed. What we would have to do, though, is transform the place/manner in
which those parts are stored. For example, to convert between #6-#7 requires
only that we redefine the four manipulation functions. To convert from
#1 to #7 entails this redefinition, and also RPLACD-ing the Being with itself (to
transfer its part/value pairs from the value cell to the property list), and finally
mapping along the list of BEINGs, defining each one as a selectq, with just those
entries (cp q), where p is executable and (p q) now appears on the prop. list of B.

A more general scheme for this process might be phrased:
	i) redefine Getb, Setb, Applyb, Condenseb, PVS	as required
       ii) use old-Getb to map along the parts of the existing structure of a BEING,
	   and for each part so accessed, use the new-Setb to properly relocate it.
      iii) condense each Being, using the new-Condenseb.


Step (ii) should be prefaced by Createb(B), to initialize a new Being structure;
perhaps this should be preceded by a Saveb(B), which sets the variables
save-exs, save-contents, save-algs,... to the appropriate part values. This is
in case Create (or Setb) might reuse the same structures that B used originally.

Saveb(B) can always be defined as mapping along Facets, assigning the associated
	variable to a copy of the result of Getb-ing that part of B.

Createb(B) might have to be redefined when representation changes. One might
	define B as a trivial sort of Selectq, with only a bottom case clause, e.g.
	for #6, but not treat B as a function at all for other representations
	(like #1). So there are really 6 functions to worry about each time:
	Getb, Setb, Applyb, PVS, Condenseb, and Createb.